package com.bjtang.book.controller;

import java.util.List;

import javax.validation.Valid;

//import java.io.File;
//import java.io.IOException;
//import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
//import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;

import com.bjtang.book.dto.ReturnDto;
import com.bjtang.book.entiy.SysUser;
import com.bjtang.book.service.MyService;
import com.bjtang.book.service.SysUserDtoService;
import com.bjtang.book.util.ReturnUtil;
//import com.bjtang.book.util.UUID生成器;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "登录用户数据管理")
@Validated
@RestController
@RequestMapping(value = "/index/")
public class IndexController {
	@Autowired
	SysUserDtoService sysUserDtoService;
	@Autowired
	MyService myService;

	@ApiOperation("获取当前用户 用户信息")
	@GetMapping("/my-user/")
	public ReturnDto GetUserByMyself() {
		return ReturnUtil.success(myService.getMyselfUser());
	}

	@ApiOperation("更新当前用户 个人信息")
	@PutMapping("/my-user/")
	public ReturnDto updateUserById(@RequestBody @Valid SysUser sysUser) {
		return ReturnUtil.success(myService.updateMyselfUser(sysUser));
	}

	@ApiOperation("查询用户列表公开信息ByidList")
	@PostMapping("/open/")
	public ReturnDto GetUserByIdList(@RequestBody List<Long> idList) {
		return ReturnUtil.success(sysUserDtoService.selectUserNameByIdList(idList));
	}
//	@ApiOperation("上传/新建图片")
//	@PostMapping("/picture2/")
//	public ReturnDto PictureUpload(@RequestParam("file") MultipartFile picture) throws IOException {
//		String pictureName = picture.getOriginalFilename();
//		String uuid = UUID生成器.generateUUID();
//		String picturePath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "static/static/图库/" + uuid
//				+ pictureName;
//		picture.transferTo(new File(picturePath));
//		System.err.println("上传成功");
//		return ReturnUtil.success();
//	}
//
//	@ApiOperation("上传/新建图片批量")
//	@PostMapping("/picture/")
//	public ReturnDto PictureUploads(@RequestParam("file") List<MultipartFile> pictures) throws IOException {
//
//		System.err.println(pictures.size());
//		for (int i = 0; i < pictures.size(); i++) {
//			String pictureName = pictures.get(i).getOriginalFilename();
//			String uuid = UUID生成器.generateUUID();
//			String picturePath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "static/static/图库/"
//					+ uuid + pictureName;
//			pictures.get(i).transferTo(new File(picturePath));
//		}
//		System.err.println("上传成功2");
//		return ReturnUtil.success();
//	}
}
